home *** CD-ROM | disk | FTP | other *** search
- Path: news1.cle.ab.com!usenet
- From: don.phillips@ab.com (Donald-Anthony C. Phillips)
- Newsgroups: comp.lang.c
- Subject: Re: need psudeo code for binary search
- Date: Fri, 01 Mar 1996 19:14:52 GMT
- Organization: The Allen-Bradley Co., Inc
- Distribution: inet
- Message-ID: <4h77mu$qtb@news1.cle.ab.com>
- References: <Pine.SOL.3.91.960229154211.27358B-100000@obelix>
- NNTP-Posting-Host: abpc386.cle.ab.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- The binary search algorithm works as follows:
- 1) Remember the structure must already be sorted.
- 2) It works better as a recursive function
-
-
- BinarySearch(key,start,end)
- find the middle element (current_position = (start + end) div 2)
- if the key == array(current_position)
- return(array(current_position))
- else if the key < array(current_position)
- BinarySearch(key,start,current_position -1)
- else if the key > current_position
- BinarySearch(key,current_position + 1, end)
- end
-
- The real question is what is its order of magnitude O(n)????
- Donald-Anthony C. Phillips
- Programmer/Analyst
- Rockwell Automation
- ---------------------------------------
- Allen-Bradley
- don.phillips@ab.com
-
-